package com.dynabook.ems.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dynabook.ems.model.bo.ChangeMachineBO;
import com.dynabook.ems.model.bo.OldMachineMessageBO;
import com.dynabook.ems.model.bo.OldModificationBO;
import com.dynabook.ems.model.dto.WorkOrderApprovalListRequest;
import com.dynabook.ems.model.dto.WorkOrderByBomNumRequest;
import com.dynabook.ems.model.dto.WorkOrderListRequest;
import com.dynabook.ems.model.entity.EmsProductionRecords;
import com.dynabook.ems.model.entity.EmsWorkOrder;
import com.dynabook.ems.model.vo.WorkOrderApprovalListVO;
import com.dynabook.ems.model.vo.WorkOrderByBomNumVO;
import com.dynabook.ems.model.vo.WorkOrderListVO;
import com.dynabook.ems.model.vo.WorkOrderMailVO;
import com.dynabook.ems.model.vo.WorkOrderExportVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
* @author tester
* @description 针对表【ems_work_order】的数据库操作Mapper
* @createDate 2025-07-28 17:23:56
* @Entity com.dynabook.ems.model.entity.EmsWorkOrder
*/
public interface EmsWorkOrderMapper extends BaseMapper<EmsWorkOrder> {
    
    /**
     * 分页查询工单列表
     * @param page 分页参数
     * @param request 查询条件
     * @return 工单列表
     */
    Page<WorkOrderListVO> pageWorkOrderList(Page<WorkOrderListVO> page, @Param("request") WorkOrderListRequest request);
    
    /**
     * 分页查询工单审批列表
     * @param page 分页参数
     * @param request 查询条件
     * @return 工单审批列表
     */
    Page<WorkOrderApprovalListVO> pageWorkOrderApprovalList(Page<WorkOrderApprovalListVO> page, @Param("request") WorkOrderApprovalListRequest request);
    
    /**
     * 根据工单号更新工单信息
     * @param workOrder 工单信息
     * @return 更新行数
     */
    int updateByWorkOrderNum(@Param("workOrder") EmsWorkOrder workOrder);


    @Select("select GETWORKORDERNO() as WORKORDERID;")
    String getWORKORDERNO();
    
    /**
     * 根据BOM号查询关联的工单号列表
     * @param bomId BOM编号
     * @return 工单号列表
     */
    List<String> getWorkOrderNumsByBomNum(@Param("bomId") String bomId);
    
    /**
     * 根据BOM号分页查询BOM详情信息
     * @param page 分页参数
     * @param request 查询条件
     * @return BOM详情分页列表
     */
    Page<WorkOrderByBomNumVO.BomDetailItem> pageBomDetailByBomNum(Page<WorkOrderByBomNumVO.BomDetailItem> page, @Param("request") WorkOrderByBomNumRequest request);

    ChangeMachineBO getFinishedProductModel(String workOrderNumber);

    List<WorkOrderMailVO> getWorkOrderListByIds(@NotEmpty(message = "工单ID列表不能为空") List<String> workOrderIds);
    
    /**
     * 查询工单导出数据
     * @param workOrderNums 工单号列表，为null时查询所有数据
     * @return 导出数据列表
     */
    List<WorkOrderExportVO> getWorkOrderExportData(@Param("workOrderNums") List<String> workOrderNums);

    OldMachineMessageBO getOldMachineMessage(String workOrderNum);

    List<OldModificationBO> getOldModification(String workOrderNum);

    List<EmsProductionRecords> getEmsProductionRecordMessage(List<String> workOrderNumbers);
}




